package com.rk.order.controller;

import com.rk.common.constant.MqConst;
import com.rk.common.result.Result;
import com.rk.common.service.RabbitService;
import com.rk.hosp.vo.msm.MsmVo;
import com.rk.hosp.vo.order.OrderMqVo;
import org.apache.catalina.connector.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 测试rabbitmq
 * @author :Rk.
 * @date : 2022/12/6
 */
@RestController
@RequestMapping("/order")
public class TestMq {

    @Autowired
    private RabbitService rabbitService;

    @GetMapping("/sendOrder/{email}")
    public Result sendMessage(@PathVariable String email){

        //发送mq信息更新号源
        OrderMqVo orderMqVo = new OrderMqVo();
        orderMqVo.setScheduleId("1");
        orderMqVo.setReservedNumber(32);
        orderMqVo.setAvailableNumber(42);

        //短信提示 模板
        MsmVo msmVo = new MsmVo();
        msmVo.setPhone(email);
        msmVo.setTemplateCode("orderTemplate");
        Map<String,Object> param = new HashMap<String,Object>(){{
            put("title", "北京第四医院内科");
            put("amount", 50);
            put("reserveDate", "2022-12-10 早上10:00");
            put("name", "王牛");
            put("quitTime","2022-12-08 15:00:00");
        }};
        msmVo.setParam(param);
        orderMqVo.setMsmVo(msmVo);
        //发送消息
        System.out.println("发送内容:"+orderMqVo);
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_ORDER,MqConst.ROUTING_ORDER,orderMqVo);
        return Result.ok();
    }
    @RequestMapping("/sendEmail")
    public Result sendEmail(){
        MsmVo msmVo=new MsmVo();
        msmVo.setPhone("1624603357@QQ.COM");
        msmVo.setTemplateCode("邮件");

        //发送消息
        System.out.println("发送内容:"+msmVo);
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MESSSAGE,MqConst.ROUTING_EMAIL,msmVo);

        return Result.ok();
    }

    @RequestMapping("/sendMSM")
    public Result sendMSM(){

        MsmVo msmVo=new MsmVo();
        msmVo.setPhone("18191691639");
        msmVo.setTemplateCode("短信");

        //发送消息
        System.out.println("发送内容:"+msmVo);
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MESSSAGE,MqConst.ROUTING_MSM,msmVo);
        return Result.ok();
    }

    public static void main(String[] args) {

        System.out.println(getValue(2));

        List<String> words = new ArrayList<>();
        words.add("hello");
        words.add("world");
        String str="";
        for (String word : words) {
            str+=word;
        }
        Set<Character> set = new HashSet<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (!set.contains(c)) {
                set.add(c);
                sb.append(c);
            }
        }
        char[] chars = sb.toString().toCharArray();

        System.out.println(chars);

    }

    public static int getValue(int i) {
        int result = 0;
        switch (i) {
            case 1:
                result = result + i;
            case 2:
                result = result + i * 2;
            case 3:
                result = result + i * 3;
        }
        return result;
    }

}
